<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'商品分类'),
);
//商品分类
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_kuaidian_group',$params,array($pindex,$psize),$total,$fields,'','star desc, id desc');
	if($list){
		foreach($list as &$item){

		}
	}	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'star','title'=>'星数_Star','type'=>'star','set'=>'star'),
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'title','title'=>'分类名称','type'=>'string'),
			array('name'=>'image','title'=>'分类图片','type'=>'image'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'batch'=>array(
			array('type'=>'post','url'=>'/group/updata/','title'=>'同步分类'),
		)),
		'search_one'=>array('name'=>'title','title'=>'商品分类名称','add'=>false),
	);
	$return['htmls']=$htmls;
	$status=array('0'=>'显示','1'=>'隐藏');
	$return['status']=$status;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kuaidian_group',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回商品分类列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'paixu','title'=>'排序','type'=>'string'),	
					array('name'=>'title','title'=>'分类名称','type'=>'string','must'=>true),
					array('name'=>'image','title'=>'分类图片','type'=>'image'),
					array('name'=>'desc','title'=>'分类描述','type'=>'string'),
					array('name'=>'status','title'=>'是否显示','type'=>'switch'),
				)),
		)
	);
	$status=array('0'=>'显示','1'=>'隐藏');	
	$return['status']=$status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('标题不能为空','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'desc'=>trim($postdata['desc']),
		'image'=>trim($postdata['image']),
		'status'=>intval($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_kuaidian_group',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{	
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_kuaidian_group',$data);
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['status'])){
		$update['status']=intval($post['status']);
	}
	if($update){
		pdo_update('jy_kuaidian_group',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='star'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['star'])){
		$update['star']=$post['star'];
	}
	if($update){
		pdo_update('jy_kuaidian_group',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
if($_RQ['op']=='updata'){
	$this->model('goods')->upgroup();
	exi('同步分类成功！');
}